<template>
  <div class="item-box">
    <block-header icon="/static/icon/tonghua.png" title="最近通话" :number="number"></block-header>
    <record-list :data="converseListTemp" v-if="converseListTemp.length > 0" :loadAll="loadAll"></record-list>
    <span v-else class="tip-null">暂无数据</span>
  </div>
</template>

<script>
  import BlockHeader from '../../components/block-header'
  import RecordList from '../../components/record-list'
  import request from '../../helper/request'

  export default {
    components: {
      BlockHeader,
      RecordList
    },
    props: {
      data: {
        type: Object,
        default() {
          return {}
        }
      }
    },
    data() {
      return {
        converseList: [],
        converseListTemp: [],
        number: ''
      }
    },
    methods: {
      /**
       * 查看全部
       */
      loadAll() {
        this.$store.commit('updatePhone', this.data)
        this.$router.push('/converse-file-all')
      },
      getQueryList(limit = 5) {
        let param = Object.assign({
          'sjh': '',
          'pageObj': {
            'currPage': 1,
            'pageSize': limit,
            'pagination': '1'
          }
        }, this.data)
        request('superRecord/mobile/txjl_zjth', 'SC042601', param).then(res => {
          this.number = res.pageResult.totalCount
          this.converseList = res.zjth.map(resTH => {
            return {
              tableName: resTH.tableName,
              systemid: resTH.systemid,
              mobile: resTH.sjhm,
              name: resTH.xm,
              time: resTH.lastTime,
              count: resTH.num,
              type: 'phone'
            }
          })
          this.converseListTemp = this.converseList.slice(0, 2)
        }).catch(err => {
          this.$toast(err.msg)
        })
      }
    },
    created() {
      this.getQueryList()
    }
  }
</script>

<style lang="scss" scoped>
</style>
